package com.cyj.spring.springframeword.beans.factory.support;

import com.cyj.spring.springframeword.beans.factory.config.SingletonBeanRegistry;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 默认的bean单例注册表
 * @BelongsProject: small-spring
 * @BelongsPackage: com.cyj.spring.springframeword.beans.factory.support
 * @Author: ChenYongJia
 * @CreateTime: 2021-07-26 14:37
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {

    private Map<String, Object> singletonObjects = new HashMap<>(16);

    /**
     * 单例化 bean
     *
     * @param beanName bean名称
     * @return java.lang.Object
     * @date 2021/7/27 15:31
     * @author ChenYongJia
     * @version 1.0
     */
    @Override
    public Object getSingleton(String beanName) {
        return singletonObjects.get(beanName);
    }

    /**
     * 添加 bean 单例
     *
     * @param beanName bean名称
     * @param singletonObject 单例对象
     * @return void
     * @date 2021/7/27 15:32
     * @author ChenYongJia
     * @version 1.0
     */
    protected void addSingleton(String beanName, Object singletonObject) {
        singletonObjects.put(beanName, singletonObject);
    }

}
